
const mongoose = require("mongoose");
const { Schema } = mongoose;
const orderSchema = new Schema({
    //预计送达时间
    estimatedDeliveryTime: { type: Number, required: true },
    userId: {
        type: mongoose.Schema.Types.ObjectId, ref: "muser",
    }, // 用户ID，关联用户表
    goodsInfo: [
        {
            goodId: { type: mongoose.Schema.Types.ObjectId, ref: "good", }, // 商品ID，关联商品表
            quantity: { type: Number, required: true, default: 0 }, // 商品数量
            sid: { type: String, required: true }, // 分组id
        }
    ],
    totalPrice: { type: Number, required: true }, // 订单总价
    status: { type: Number, required: true, default: 1 }, // 订单状态 1: 待支付 2: 已支付 3: 已取消 
    createdAt: { type: Number, default: Date.now }, // 创建时间
    couponId: { type: mongoose.Schema.Types.ObjectId, ref: "coupon" }, // 优惠券ID，关联优惠券表
    paymentMethod: { type: Number, default: 1 }, // 支付方式 1: 在线支付 2: 货到付款 3: 在线支付+货到付款
    // shippingAddress: { type: String, required: true }, // 配送地址
    addressId: { type: mongoose.Schema.Types.ObjectId, ref: "address", }, // 配送地址
    notes: { type: String, default: '' } // 订单备注

});
const order = mongoose.model("order", orderSchema);
module.exports = order